package cn.stylefeng.guns.sys.modular.tao.service.serviceImpl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.modular.tao.entity.StockSku;
import cn.stylefeng.guns.sys.modular.tao.mapper.StockSkuMapper;
import cn.stylefeng.guns.sys.modular.tao.model.params.StockSkuParam;
import cn.stylefeng.guns.sys.modular.tao.model.result.StockSkuResult;
import  cn.stylefeng.guns.sys.modular.tao.service.StockSkuService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 库存规格表 服务实现类
 * </p>
 *
 * @author 
 * @since 2019-09-11
 */
@Service
public class StockSkuServiceImpl extends ServiceImpl<StockSkuMapper, StockSku> implements StockSkuService {

    @Override
    public void add(StockSkuParam param){
        StockSku entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(StockSkuParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(StockSkuParam param){
        StockSku oldEntity = getOldEntity(param);
        StockSku newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public StockSkuResult findBySpec(StockSkuParam param){
        return null;
    }

    @Override
    public List<StockSkuResult> findListBySpec(StockSkuParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(StockSkuParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(StockSkuParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private StockSku getOldEntity(StockSkuParam param) {
        return this.getById(getKey(param));
    }

    private StockSku getEntity(StockSkuParam param) {
        StockSku entity = new StockSku();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
